layui.define(['table', 'form','laydate'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form,laydate=layui.laydate;

    laydate.render({
        elem: '#searchDate'
        ,range: true
    });

    table.render({
      elem: '#LAY-table'
      ,url: layui.setter.webRoot + '/device/iot_logs/list.data'
      ,method: 'post'
      ,parseData: function (res) {
          return {
              "code": res.code,
              "msg": res.msg,
              "count": res.body.total,
              "data": res.body.data
          };
      }
      ,response: {statusCode: 200}
      ,cols: [[
        {field: 'msgId', title: '消息ID'}
        ,{field: 'iotTopic', title: 'IOT主题'}
        ,{field: 'iotId', title: 'IOT信息',templet:function(record){
            return record.protocolType + '['+ record.iotId+']';
        }}
        ,{field: 'deviceSn',title: '设备序列号'}
        ,{field: 'typeName',title: '类型'}
        ,{field: 'command',title: '命令'}
        ,{field: 'content',title: '内容'}
        ,{field: 'createDate', title: '创建时间'}
      ]]
      ,page: true
      ,limit: 30
      ,height: 'full-220'
      ,text: '对不起，加载出现异常！'
    });
  
  //监听搜索
  form.on('submit(LAY-search)', function(data){
    var field = data.field;
    //执行重载
    table.reload('LAY-table', {
      where: field
      ,page: {curr: 1}
    });
  });
  
  //事件
  var active = {};
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('device_iot_logs_list', {})
});